import request from "@/api";
import { BaseRet, ObjectRet } from "../response";
import { FileEnum } from "@/enums/FileEnum";

class FileApi {
  /**
   * 上传文件
   * @returns
   */
  static async UploadFile(data: FileModel): Promise<BaseRet> {
    return await request({
      url: "/File/UploadFile",
      headers: { "Content-Type": "multipart/form-data" },
      method: "post",
      data: data,
    });
  }

  /**
   * 单上传文件
   * @returns
   */
  static async UploadSingleFile(data: FileModel): Promise<ObjectRet<SingleFileRet>> {
    return await request({
      url: "/File/UploadSingleFile",
      headers: { "Content-Type": "multipart/form-data" },
      method: "post",
      data: data,
    });
  }

  /** 获取系统默认头像 */
  static GetDefaultUserAvatar() {
    return new URL("@/assets/img/avatar.jpg", import.meta.url).href;
  }
}

export default FileApi;

export interface FileModel {
  mainId: string;
  module: FileEnum;
  file?: any;
}

export interface SingleFileRet {
  fileId: string;
  fileUrl: string;
}

export interface SingleImageFileRet {
  id: string;
  base64Image: string;
}
